#include "sock.hpp"
// epoll封装
class Epoll
{
public:
    Epoll() = default;
    int Epoll_Create()
    {
        _epfd = epoll_create(EPOLL_CREATE_NUM);
        if (_epfd < 0)
        {
            cout << strerror(errno) << endl;
            return _epfd;
        }
        return _epfd;
    }
    void Epoll_Ctl(int op, int fd, uint32_t event)
    {
        epoll_event events;
        events.data.fd = fd;
        events.events = event;
        int ret = epoll_ctl(_epfd, op, fd, &events);
        if (ret < 0)
        {
            cout << strerror(errno) << " 26" << endl;
            exit(6);
        }
    }
    int Epoll_Wait(epoll_event *events, int maxnum, int timeout)
    {
        int num = epoll_wait(_epfd, events, maxnum, timeout);
        if (num < 0)
        {
            cout << strerror(errno) << endl;
            exit(5);
        }
        return num;
    }
    ~Epoll()
    {
        if (_epfd > 0)
            close(_epfd);
    }

private:
    int _epfd;
};